﻿using System.Data.SqlClient;
using System.Linq;
using GSQ.BusinessEntities;
using GSQ.DataAccess.DataSetTableAdapters;

namespace GSQ.DataAccess
{
    public class SystemConfigDA
    {
        private SISTEM_CONFIGTableAdapter Adapter = new SISTEM_CONFIGTableAdapter();
        private DataSet.SISTEM_CONFIGDataTable entities;
        private DataSet.SISTEM_CONFIGRow entity;       

        public SYSTEM_CONFIG Get()
        {
            using (SqlConnection cnn = new SqlConnection(Connection.GetConnectionString))
            {
                try
                {
                    cnn.Open();
                    this.Adapter.Connection = cnn;
                    entity = this.Adapter.GetData().FirstOrDefault();

                    SYSTEM_CONFIG Sys;

                    if (entity != null)
                    {
                        Sys = new SYSTEM_CONFIG();
                        Sys.PRINTER_NAME_CONTADO = entity.PRINTER_NAME_CONTADO;
                        Sys.PRINTER_NAME_CREDITO = entity.PRINTER_NAME_CREDITO;
                        Sys.RUTA_IMAGENES = entity.RUTA_IMAGENES;
                        Sys.RUTA_REPORTES = entity.RUTA_REPORTES;
                    }
                    else
                        Sys = null;

                    return Sys;
                }
                finally
                {
                    if (cnn.State != System.Data.ConnectionState.Closed)
                        cnn.Close();
                }
            }
        }     
    }
}
